package com.jeff.android.lab.android.lifecycle.viewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

public class ActivityViewModel extends ViewModel {

    private MutableLiveData<String> mLiveData;

    public LiveData<String> getData() {
        if (mLiveData == null)
            mLiveData = new MutableLiveData<>();
//        mLiveData.setValue("Hello, ViewModel");
        return mLiveData;
    }

    public void setData(String value) {
        if (mLiveData == null)
            mLiveData = new MutableLiveData<>();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(3000);
                    mLiveData.postValue(value);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
//        mLiveData.setValue(value);
    }

}
